package com.hotel.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hotel.dao.mapper.RoomInfoMapper;
import com.hotel.entity.OrderResult;
import com.hotel.entity.RoomInfo;
import com.hotel.entity.RoomInfoExample;
import com.hotel.service.OrderService;
import com.hotel.utils.Message;



@Service("orderService")
public class OrderServiceImpl implements OrderService{

	@Resource  
    private RoomInfoMapper roomInfoMapper;
	
	@Override
	public List<RoomInfo> typeSelect(int hotelId, int floor_no, String room_type) {
		RoomInfoExample example = new RoomInfoExample();
		RoomInfoExample.Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(hotelId).andFloorNoEqualTo(floor_no);
		List<RoomInfo> list = roomInfoMapper.selectByExample(example);
		

		return list;
	}

	@Override
	public List<RoomInfo> typeSelect(int hotelId, int floor_no) {
		RoomInfoExample example = new RoomInfoExample();
		RoomInfoExample.Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(hotelId).andFloorNoEqualTo(floor_no);
		List<RoomInfo> list = roomInfoMapper.selectByExample(example);
		
		return list;
	}

	@Override
	public List<RoomInfo> typeSelect(int hotelId, String room_type) {
		RoomInfoExample example = new RoomInfoExample();
		RoomInfoExample.Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(hotelId).andRoomDeviceIdsEqualTo(room_type);
		List<RoomInfo> list = roomInfoMapper.selectByExample(example);
		
		return list;
	}

	@Override
	public OrderResult orderRoom(int room_info_id) {
		OrderResult or = new OrderResult();
		String message = "";
		RoomInfo roomInfo = roomInfoMapper.selectByPrimaryKey(room_info_id);
		
		if (roomInfo == null) {
			message = Message.Message_8003;
			or.setMessage(message);
			or.setRoomInfo(null);
			return or;
		}
		
		roomInfo.setStatus(1);
		
		if(1 == roomInfoMapper.updateByPrimaryKey(roomInfo)){
			message =  Message.Message_7000;
			or.setRoomInfo(roomInfo);
		}
		else{
			message = Message.Message_8000;
			or.setRoomInfo(null);
		} 
		
		or.setMessage(message);
		
		return or;
		
	}

	@Override
	public String orderVerify(int room_info_id) {
		RoomInfo roomInfo = roomInfoMapper.selectByPrimaryKey(room_info_id);
		
		if (roomInfo == null) {
			return Message.Message_8003;
		}
		//可预约
		if(0 == roomInfo.getStatus()){
			return Message.Message_7001;
		}
		//不可预约
		else if(1 == roomInfo.getStatus()){
			return Message.Message_8001;
		}
		
		return Message.Message_8002;
	}
	

}
